<template>
	<u-tabbar v-model="current" v-bind="tabbarStyle" :list="tabbarList" @change="handleChange" :hide-tab-bar="false"
		mid-button></u-tabbar>
</template>

<script lang="ts" setup>
	import { useAppStore } from '@/stores/app'
	import { navigateTo } from '@/utils/util'
	import { computed, ref } from 'vue'
	const current = ref()
	const appStore = useAppStore()
	const tabbarList = computed(() => {
		let res = appStore.getTabbarConfig.map((item : any) => {
			const link = JSON.parse(item.link)
			return {
				iconPath: item.unselected,
				selectedIconPath: item.selected,
				text: item.name,
				link,
				pagePath: link.path
			}
		})
		let newObject = {
			iconPath: "/static/images/center-btn.png",
			selectedIconPath: "/static/images/center-btn.png",
			text: '发布',
			midButton: true,
			link: { "path": "/pages/release/release", "name": "发布", "type": "shop" },
			pagePath: '/pages/release/release'
		}
		let middleIndex = Math.floor(res.length / 2)
		res.splice(middleIndex, 0, newObject)
		return res
	})

	const tabbarStyle = computed(() => ({
		activeColor: appStore.getStyleConfig.selectedColor,
		inactiveColor: appStore.getStyleConfig.defaultColor
	}))
	const handleChange = (index : number) => {
		const selectTab = tabbarList.value[index]

		navigateTo(selectTab.link, 'reLaunch')
	}
</script>